package 反射4;

import java.lang.reflect.Method;

/**
 * @Auther:lele
 * @Date:2025/3/13
 */
public class TestBemo {
    public static void main(String[] args) throws Exception {
        Student student = new Student();
        Teacher teacher = new Teacher();
        String type = getType(teacher);
        System.out.println("type = " + type);


    }



//    获取对象类型
    public static void getTy(Object obj){
        Class<?> aClass = obj.getClass();
        Method[] declaredMethods = aClass.getDeclaredMethods();


    }







//获取对象类型  反射
    public static String getType(Object obj) throws Exception {
        Class<?> aClass = obj.getClass();
        Object o = aClass.newInstance();

        Method getUserType = aClass.getDeclaredMethod("getUserType", String.class);
        String invoke1 = (String) getUserType.invoke(o, "王晓晓");
        return invoke1;
    }
}
